home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / ASM / GCSWEEP.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-06-09  |  8.5 KB  |  311 lines

  1. ;* GCSWEEP.ASM
  2. ;************************************************************************
  3. ;*                                    *
  4. ;*        PC Scheme/Geneva 4.00 Borland TASM code            *
  5. ;*                                    *
  6. ;* (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  7. ;* (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  8. ;*                                    *
  9. ;*----------------------------------------------------------------------*
  10. ;*                                    *
  11. ;*        Scan all pages and move objects to relocate        *
  12. ;*                                    *
  13. ;*----------------------------------------------------------------------*
  14. ;*                                    *
  15. ;* Created by: John Jensen        Date: 1985            *
  16. ;* Revision history:                            *
  17. ;* - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  18. ;*                                    *
  19. ;*                    ``In nomine omnipotentii dei''    *
  20. ;************************************************************************
  21. IDEAL
  22. %PAGESIZE    60, 132
  23. MODEL   medium
  24. LOCALS    @@
  25.  
  26.     INCLUDE    "scheme.ash"
  27.  
  28. CODESEG
  29.  
  30. ;************************************************************************
  31. ;*                gcsweep                    *
  32. ;************************************************************************
  33. PROC C  gcsweep USES si di
  34.     push    ds             ; set es to point to the current DS
  35.     pop    es
  36.     mov    ax, END_LIST
  37.     mov    cx, NUMTYPES
  38.     lea    di, [pagelist]         ; load table address
  39.     cld
  40.     rep    stosw            ; initialize the pagelist table
  41.     mov    dx, NUMPAGES
  42. @@loop:
  43.     dec    dx
  44.     cmp    dx, DEDPAGES-1
  45.     ja    @@more
  46.     ret
  47.  
  48. @@more:
  49.     push    dx
  50.     call    swpage C, dx        ; "sweep" the page (GC it)
  51.     pop    dx
  52.     mov    bx, dx             ; use current page number as index
  53.     sal    bx, 1
  54.     test    [attrib+bx], NOMEMORY     ; is page frame allocated?
  55.     jnz    @@loop
  56.     mov    ax, dx
  57.     mov    si, [WORD ptype+bx]
  58.     xchg    [pagelist+si], ax     ; pagelist[type] <- page
  59.     mov    [pagelink+bx], ax     ; pagelink[page] <- old pagelist[type]
  60.     jmp    @@loop
  61. ENDP    gcsweep
  62.  
  63. ;************************************************************************
  64. ;*                swpage                    *
  65. ;************************************************************************
  66. PROC C    swpage    USES si di, @@pageno:WORD
  67.     mov    bx, [@@pageno]        ; current page allocated ?
  68.     sal    bx, 1
  69.     test    [attrib+bx], NOMEMORY    ; allocated?
  70.     jz    @@proceed
  71. @@fixnum:                ; Fixnums & chars handled as immediates
  72. @@char:
  73. @@free:                    ; Why are we processing a free page?
  74. @@return:
  75.     ret
  76.  
  77. @@proceed:
  78.     mov    di, [WORD ptype+bx]    ; Dispatch on the page type
  79.     cmp    di, FREETYPE
  80.     je    @@free
  81.     ldpage    es, bx             ; define base paragraph for this page
  82.     jmp    [@@table+di]
  83. DATASEG
  84. @@table    DW    @@list             ; [0] List cells
  85.     DW    @@fixnum         ; [1] Fixnums
  86.     DW    @@flonum         ; [2] Flonums
  87.     DW    @@bignum         ; [3] Bignums
  88.     DW    @@symbol         ; [4] Symbols
  89.     DW    @@string         ; [5] Strings
  90.     DW    @@array         ; [6] Arrays
  91.     DW    @@continuation         ; [7] Continuations
  92.     DW    @@closure         ; [8] Closures
  93.     DW    @@free             ; [9] Free space (unallocated)
  94.     DW    @@code             ; [10] Code
  95.     DW    @@inline        ; [11] Inline code
  96.     DW    @@port             ; [12] Port data objects
  97.     DW    @@char             ; [13] Characters
  98.     DW    @@environment         ; [14] Environments
  99. CODESEG
  100.  
  101. @@list:                    ; List Cells & fixed length pointer objects
  102.     mov    ax, SIZE LISTDEF
  103.     xor    si, si
  104.     xor    di, di             ; zero referenced cell counter
  105.     mov    cx, END_LIST
  106.     mov    dl, SPECFREE*2
  107.     push    bx             ; save page number index
  108.     mov    bx, [psize+bx]
  109.     sub    bx, ax             ; adjust length for boundary check
  110. @@listloop:
  111.     test    [(LISTDEF es:si).gc], GC_BIT
  112.     jnz    @@listmarked
  113.     mov    [(FREELISTDEF es:si).next], cx
  114.     mov    [(FREELISTDEF es:si).tag], dl
  115.     mov    cx, si
  116.     jmp    @@listnext
  117. @@listmarked:
  118.     and    [(LISTDEF es:si).gc], NOT GC_BIT
  119.     inc    di             ; increment referenced cell counter
  120. @@listnext:
  121.     add    si, ax
  122.     cmp    si, bx             ; test for end of page
  123.     jbe    @@listloop
  124.                     ; end of page update free list header
  125.     pop    bx             ; restore page table index
  126.     mov    [nextcell+bx], cx
  127.     or    di, di             ; any referenced cells in this page?
  128.     jnz    @@return
  129.     mov    [ptype+bx], FREETYPE     ; mark empty page as free
  130.     mov    [attrib+bx], 0
  131.     jmp    @@return
  132.  
  133. @@flonum:                    ; Process Page of Flonums
  134.     mov    ax, SIZE FLODEF
  135.     xor    si, si
  136.     xor    di, di             ; zero referenced cell counter
  137.     mov    cx, END_LIST
  138.     mov    dl, FREETYPE
  139.     push    bx             ; save page number index
  140.     mov    bx, [psize+bx]
  141.     sub    bx, ax             ; adjust for boundary check
  142. @@floloop:
  143.     cmp    [(FLODEF es:si).tag], dl ; tag = free?
  144.     je    @@flofree
  145.     test    [(FLODEF es:si).gc], GC_BIT
  146.     jnz    @@flomarked
  147.     mov    [(FREEFLODEF es:si).tag], dl
  148. @@flofree:
  149.     mov    [(FREEFLODEF es:si).next], cx
  150.     mov    cx, si
  151.     jmp    @@flonext
  152. @@flomarked:
  153.     and    [(FLODEF es:si).gc], NOT GC_BIT
  154.     inc    di             ; increment referenced cell counter
  155. @@flonext:
  156.     add    si, ax
  157.     cmp    si, bx             ; test for end of page
  158.     jbe    @@floloop
  159.                     ; end of page update free flo header
  160.     pop    bx             ; restore page table index
  161.     mov    [nextcell+bx], cx
  162.     or    di, di             ; any referenced cells in this page?
  163.     jnz    @@floreturn
  164.     mov    [ptype+bx], FREETYPE     ; mark empty page as free
  165.     mov    [attrib+bx], 0
  166. @@floreturn:
  167.     jmp    @@return
  168.  
  169. @@bignum:                    ; Process variable length data object
  170. @@symbol:
  171. @@string:
  172. @@inline:
  173. @@array:
  174. @@closure:
  175. @@continuation:
  176. @@code:
  177. @@environment:
  178.     xor    si, si
  179.     mov    di, -1
  180.     push    bx             ; save page table index
  181.     mov    bx, [psize+bx]
  182.     sub    bx, SIZE POINTER     ; adjust size for boundary check
  183. @@dataloop:
  184.     mov    dx, [(ANYDEF es:si).len]
  185.     or    dx, dx
  186.     jge    @@bigstr
  187.     mov    dx, OFFSET (TYPE STRDEF).buffer + SIZE POINTER
  188. @@bigstr:
  189.     test    [(ANYDEF es:si).gc], GC_BIT
  190.     jnz    @@datamarked
  191.     or    di, di            ; Combine with previous free area ?
  192.     jge    @@datacombine
  193.     mov    [(ANYDEF es:si).tag], FREETYPE
  194.     mov    [(ANYDEF es:si).len], dx
  195.     mov    di, si             ; Remember object not referenced
  196.     jmp    @@datanext
  197. @@datacombine:
  198.     add    [(ANYDEF es:di).len], dx
  199.     jmp    @@datanext
  200. @@datamarked:
  201.     and    [(ANYDEF es:si).gc], NOT GC_BIT
  202.     mov    di, -1             ; Remember last object was referenced
  203. @@datanext:
  204.     add    si, dx             ; Increment area pointer by block length
  205.     cmp    si, bx             ; Last object in block?
  206.     jb    @@dataloop
  207. @@finished:
  208.     pop    bx
  209.     or    di, di            ; last block free ?
  210.     jl    @@lastnotfree
  211.     sub    si, [psize+bx]         ; Adjust in case last byte of page not accounted for
  212.     neg    si
  213.     add    [(ANYDEF es:di).len], si
  214.     mov    [nextcell+bx], di     ; Update free pool header
  215.     or    di, di             ; is page empty?
  216.     jnz    @@datareturn
  217.     mov    [ptype+bx], FREETYPE     ; mark page as being free
  218.     mov    [attrib+bx], 0
  219.     cmp    bl, [emsbias]        ; is this page in EMS ? if so, it
  220.     jae    @@smallpage        ; can't be a big page
  221.     mov    ax, [psize+bx]
  222.     cmp    ax, [defpagesize]
  223.     ja    @@fixbig
  224. @@smallpage:
  225.     jmp    @@return
  226. @@lastnotfree:
  227.     mov    [nextcell+bx], END_LIST ; Indicate no free pool
  228. @@datareturn:
  229.     jmp    @@return
  230.  
  231. @@port:                    ; ports -- close any open files
  232.     xor    si, si
  233.     mov    di, -1
  234.     push    bx             ; save page table index
  235.     mov    bx, [psize+bx]
  236.     sub    bx, SIZE POINTER    ; adjust size for boundary check
  237. @@portloop:
  238.     mov    dx, [(PORTDEF es:si).len]
  239.     test    [(PORTDEF es:si).gc], GC_BIT
  240.     jnz    @@portmarked
  241.     cmp    [(PORTDEF es:si).tag], FREETYPE
  242.     je    @@portok
  243.     test    [(PORTDEF es:si).pflags], PORT_OPEN ; open ?
  244.     jz    @@portok
  245.     push    bx dx
  246.     mov    bx, [(PORTDEF es:si).pflags]
  247.     and    bx, PORT_TYPE
  248.     cmp    bx, TYPE_FILE
  249.     jne    @@noclose
  250.     mov    bx, [(PORTDEF es:si).handle] ; close file
  251.     call    close C, bx
  252. @@noclose:
  253.     pop    dx bx
  254. @@portok:                  ; combine with previous free area?
  255.     or    di, di
  256.     jge    @@portcombine
  257.     mov    [(PORTDEF es:si).tag], FREETYPE
  258.     mov    di, si            ; remember object not referenced
  259.     jmp    @@portnext
  260. @@portcombine:
  261.     add    [(PORTDEF es:di).len], dx
  262.     jmp    @@portnext
  263. @@portmarked:
  264.     and    [(PORTDEF es:si).gc], NOT GC_BIT
  265.     mov    di, -1             ; Remember last object was referenced
  266. @@portnext:
  267.     add    si, dx             ; Increment area pointer by block length
  268.     cmp    si, bx             ; Last object in block?
  269.     jb    @@portloop
  270.     jmp    @@finished
  271.  
  272. @@fixbig:                 ; Restore memory management tables due
  273.                     ;  to release of large page
  274.     mov    cx, [defpagesize]
  275.     mov    ax, cx             ; page size of large page <- default
  276.     xchg    ax, [psize+bx]
  277.     ldpage    dx, bx         ; load para address of large page
  278.     mov    bx, cx
  279.     shr    cx, 1            ; cx <- pagesize/16
  280.     shr    cx, 1
  281.     shr    cx, 1
  282.     shr    cx, 1
  283. @@fixloop:
  284.     sub    ax, bx            ; decrease big page size by one page
  285.     jbe    @@fixreturn
  286.     add    dx, cx             ; compute pointer to next physical page
  287.     mov    si, DEDPAGES*2         ; initialize page table index
  288. @@fixmore:
  289.     ldpage    di, si         ; is this the page we're looking for?
  290.     cmp    dx, di
  291.     je    @@fixfound
  292.     add    si, 2             ; increment the page table index
  293.     cmp    si, NUMPAGES*2         ; more pages?
  294.     jl    @@fixmore
  295.         lea     bx, [@@msg]             ; error-- loop should not exit
  296. DATASEG
  297. @@msg   DB     "[VM INTERNAL ERROR] swpage: logical page not found", LF, 0
  298. CODESEG
  299.     call    print_and_exit C, bx     ; print error message and exit
  300. @@fixfound:
  301.     mov    [psize+si], bx         ; reset page size to default
  302.     mov    [attrib+si], 0         ; reset "no memory" bit in attribute table
  303.     mov    [ptype+si], FREETYPE     ; mark page as free
  304.     jmp    @@fixloop
  305. @@fixreturn:
  306.     jmp    @@return
  307. ENDP    swpage
  308.  
  309.     END
  310.  
  311.